<template>
	<main-content
		:tableHeight.sync="tableHeight"
		:otherDependenComponents="otherDependenComponents"
	>
		<template slot="query">
			<el-form ref="form" :inline="true" :model="queryData">
				<el-form-item
					:label="$t('common.belong_merchant')"
					prop="merchantId"
				>
					<merchant-select
						v-model="queryData.merchantId"
					></merchant-select>
				</el-form-item>
				<el-form-item label="提款时间">
					<el-date-picker
						v-model="queryData.createDt"
						size="medium"
						:picker-options="pickerShortcut2"
						format="yyyy-MM-dd HH:mm:ss"
						type="datetimerange"
						range-separator="-"
						:start-placeholder="$t('common.start_date')"
						:end-placeholder="$t('common.end_date')"
						align="right"
						:clearable="true"
						value-format="timestamp"
						:default-time="defaultTime"
					></el-date-picker>
				</el-form-item>
				<el-form-item label="银行卡号">
					<el-input
						clearable
						v-model="queryData.cardNumber"
						placeholder="请输入"
					/>
				</el-form-item>
				<el-form-item label="银行名称">
					<el-input
						queryData
						v-model="queryData.bankName"
						placeholder="请输入"
					/>
				</el-form-item>
				<!-- <el-form-item>
					<el-input
						v-model="selectSearchVal"
						clearable
						size="medium"
						:placeholder="$t('common.please_enter')"
					>
						<el-select
							slot="prepend"
							v-model="selectSearchType"
							style="width: 120px"
							:placeholder="$t('common.please_choose')"
						>
							<el-option
								:label="$t('agent.agent_account')"
								:value="1"
							></el-option>

							<el-option label="持卡人" :value="4"></el-option>
						</el-select>
					</el-input>
				</el-form-item> -->
				<el-form-item :label="$t('agent.agent_account') + ':'">
					<el-input
						v-model="selectSearchVal"
						clearable
						size="medium"
						:placeholder="$t('common.please_enter')"
					/>
				</el-form-item>
				<el-form-item :label="$t('agent.account_type') + ':'">
					<el-select
						v-model="queryData.accountType"
						size="medium"
						:placeholder="$t('common.all')"
						clearable
					>
						<el-option
							v-for="item in accountTypeArr"
							:key="item.code"
							:label="item.description"
							:value="item.code"
						></el-option>
					</el-select>
				</el-form-item>
				<el-form-item :label="$t('common.risk_control_level') + ':'">
					<el-select
						v-model="queryData.accountWindControl"
						size="medium"
						:placeholder="$t('common.all')"
						clearable
						multiple
						style="width: 220px"
					>
						<el-option
							v-for="item in vipDict"
							:key="item.id"
							:label="item.windControlLevelName"
							:value="item.windControlLevelName"
						></el-option>
					</el-select>
				</el-form-item>
				<el-form-item style="margin-left: 8px">
					<el-button
						type="primary"
						icon="el-icon-search"
						:disabled="loading"
						size="medium"
						@click="search"
					>
						{{ $t('common.search') }}
					</el-button>
					<el-button
						icon="el-icon-refresh-left"
						:disabled="loading"
						size="medium"
						@click="reset"
					>
						{{ $t('common.reset') }}
					</el-button>
				</el-form-item>
			</el-form>
		</template>
		<template slot="content">
			<el-table
				v-loading="loading"
				element-loading-spinner="el-icon-loading"
				border
				size="mini"
				class="small-size-table"
				:data="dataList"
				style="width: 100%"
				:header-cell-style="getRowClass"
				highlight-current-row
				:max-height="tableHeight"
			>
				<el-table-column
					prop="userName"
					align="center"
					:label="$t('agent.agent_account')"
					width="180"
				>
					<template slot-scope="scope">
						<Copy
							v-if="!!scope.row.userName"
							:title="scope.row.userName"
							:copy="copy"
						/>
						<span v-else>-</span>
					</template>
				</el-table-column>
				<el-table-column
					prop="accountType"
					align="center"
					label="账号类型"
					width="180"
				>
					<template slot-scope="scope">
						<span>
							{{
								typeFilter(scope.row.accountType, 'accountType')
							}}
						</span>
					</template>
				</el-table-column>
				<el-table-column
					prop="accountType"
					align="center"
					:label="$t('common.belong_merchant')"
					width="120"
				>
					<template slot-scope="scope">
						{{ scope.row.merchantName || '-' }}
					</template>
				</el-table-column>
				<el-table-column
					prop="cardNumber"
					align="center"
					:label="$t('agent.bank_card_no')"
					width="260"
				>
					<template slot-scope="scope">
						{{ scope.row.cardNumber || '-' }}
					</template>
				</el-table-column>
				<el-table-column
					prop="bankName"
					align="center"
					:label="$t('agent.bank_name')"
					width="230"
				>
					<template slot="header">
						{{ $t('agent.bank_name') }}
						<br />
						{{ $t('agent.bank_sub_branch') }}
					</template>
					<template slot-scope="scope">
						<span>{{ scope.row.bankName || '-' }}</span>
					</template>
				</el-table-column>
				<el-table-column
					prop="cnName"
					align="center"
					:label="$t('agent.card_holder_people')"
					width="160"
				>
					<template slot-scope="scope">
						{{ scope.row.cnName || '-' }}
						<!-- <Copy
								v-if="!!scope.row.cnName"
								:title="scope.row.cnName"
								:copy="copy"
							/>
							<span v-else>-</span> -->
					</template>
				</el-table-column>
				<!-- <el-table-column
						prop="bankAddress"
						align="center"
						:label="$t('agent.account_opening_address')"
						width="230"
					>
						<template slot-scope="scope">
							<span>{{ scope.row.bankAddress || '-' }}</span>
						</template>
					</el-table-column> -->
				<el-table-column
					prop="accountWindControl"
					align="center"
					:label="$t('common.risk_control_level')"
					width="160"
				>
					<template slot-scope="scope">
						<span>
							{{ scope.row.accountWindControl || '-' }}
						</span>
					</template>
				</el-table-column>
				<el-table-column
					prop="withdrawalTime"
					align="center"
					:label="$t('agent.withdrawal_time')"
					min-width="200"
				>
					<template slot-scope="scope">
						<span>{{ scope.row.withdrawalTime || '-' }}</span>
					</template>
				</el-table-column>
			</el-table>
			<!-- 分页 -->
			<el-pagination
				v-show="!!total"
				:current-page.sync="pageNum"
				class="pageValue"
				background
				layout="total, sizes,prev, pager, next, jumper"
				:page-size="pageSize"
				:page-sizes="$store.getters.pageSizes"
				:total="total"
				@current-change="handleCurrentChange"
				@size-change="handleSizeChange"
			></el-pagination>
		</template>
	</main-content>
</template>

<script>
import list from '@/mixins/list'
import dayjs from 'dayjs'
import { routerNames } from '@/utils/consts'
import { filterEmptyParams } from '@/utils'
import MainContent from '@/components/MainContent/index.vue'
// import { notSpecial2, isHaveEmoji } from '@/utils/validate'
const start = () =>
	dayjs()
		.startOf('day')
		.valueOf()
const end = () =>
	dayjs()
		.endOf('day')
		.valueOf()
// import { UTable } from 'umy-ui'

export default {
	name: routerNames.agentBankCard,
	components: {
		MainContent
	},
	mixins: [list],
	data() {
		this.loadData = this.throttle(this.loadData, 1000)
		return {
			tableHeight: 480,
			otherDependenComponents: [],
			queryData: {
				createDt: [start(), end()],
				userName: undefined,
				accountType: [],
				cardNumber: undefined,
				bankName: undefined,
				cnName: undefined,
				accountWindControl: undefined,
				orderType: undefined
			},
			selectSearchVal: '',
			selectSearchType: 1,
			dataList: [],
			total: 0,
			vipDict: []
		}
	},
	computed: {
		accountTypeArr() {
			return this.globalDics.accountType || []
		}
	},
	created() {
		this.getMerchantDict()
	},
	mounted() {},
	methods: {
		loadData() {
			this.dataList = []
			this.loading = true

			this.queryData.userName = ''
			// this.queryData.bankName = ''
			this.queryData.cnName = ''
			if (this.selectSearchType === 1) {
				this.queryData.userName = this.selectSearchVal
			} else if (this.selectSearchType === 3) {
				// this.queryData.bankName = this.selectSearchVal
			} else if (this.selectSearchType === 4) {
				this.queryData.cnName = this.selectSearchVal
			}
			const create = this.queryData.createDt || []
			const [startTime, endTime] = create
			let params = {
				...this.queryData,
				beginDate: startTime
					? dayjs(startTime).format('YYYY-MM-DD HH:mm:ss')
					: undefined,
				endDate: endTime
					? dayjs(endTime).format('YYYY-MM-DD HH:mm:ss')
					: undefined
			}
			params = {
				...this.getParams(params),
				accountWindControl: params.accountWindControl
					? params.accountWindControl.join(',')
					: undefined
			}
			delete params.createDt
			params.accountType = params?.accountType?.length
				? params.accountType
				: undefined
			this.$api
				.agentBankRecordAPI(filterEmptyParams(params))
				.then((res) => {
					if (res?.code === 200) {
						const { record, totalRecord } = res.data || {}
						this.dataList = Array.isArray(record)
							? Object.freeze(record)
							: []
						this.total = totalRecord || 0
					} else {
						this.$message({
							message:
								res?.msg ||
								this.$t('agent.interface_exceptions'),
							type: 'error'
						})
					}
					this.loading = false
				})
				.catch(() => (this.loading = false))
		},
		getMerchantDict(val) {
			this.$api
				.getSelectWindControlLevel({ windControlType: 3 })
				.then((res) => {
					const { data, msg } = res
					if (res?.code === 200) {
						this.vipDict = data || []
					} else {
						this.$message({
							message: msg,
							type: 'error'
						})
					}
				})
		},
		// getWindControllerLevelDict() {
		// 	this.$api
		// 		.getWindControllerLevelDict({ windControlType: 3 })
		// 		.then((res) => {
		// 			if (res?.code === 200) {
		// 				this.vipDict = res.data || []
		// 			}
		// 		})
		// },
		reset() {
			this.pageNum = 1
			this.selectSearchVal = ''
			this.selectSearchType = 1
			this.$refs['form'].resetFields()
			this.queryData = {
				createDt: [start(), end()],
				userName: undefined,
				accountType: [],
				windControlId: undefined,
				cardNumber: undefined,
				bankName: undefined,
				cnName: undefined,
				orderType: undefined
			}
			this.loadData()
		}
	}
}
</script>

<style lang="scss" scoped>
::v-deep .el-dialog__header {
	text-align: center;
	color: #909399;
	font-weight: 700;
}
::v-deep .el-input-group__prepend {
	background-color: #fff;
}
</style>
